var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.concat(b, true); // a,b 不变， c = ["a", "b", "c", "x", "y", "z", true]

var a = ['a', 'b', 'c'];
a.push('d');
var c = a.join(''); // 'abcd'

var a = ['a', 'b', 'c'];
var c = a.pop();  // a = ['a', 'b']， c = 'c'

Array.method('pop', function () {
    return this.splice(this.length - 1, 1)[0];
});

var a = ['a', 'b', 'c'];
var b = ['x', 'y', 'z'];
var c = a.push(b, true);
// a = ['a', 'b', 'c', ['x', 'y', 'z'], true];
// c = 5;

Array.method('push', function () {
    this.splice.apply(this, [this.length, 0].concat(Array.prototype.slice.apply(arguments)));

    return this.length;
});

var a = ['a', 'b', 'c'];
var b = a.reverse();  // a 和 b 都是 ['c', 'b', 'a']


var a = ['a', 'b', 'c'];
var c = a.shift();  // a = ['b', 'c']; c = 'a';

Array.method('shift', function () {
    return this.splice(0, 1)[0];
});

var a = ['a', 'b', 'c'];
var b = a.slice(0, 1);  // b = ['a'];
var c = a.slice(1);     // c = ['b', 'c'];
var d = a.slice(3);     // d = [];
var e = a.slice(-1);    // e = ['c'];
var f = a.slice(-3);    // f = ['a', 'b', 'c'];
var g = a.slice(-4);    // g = ['a', 'b', 'c'];
var h = a.slice(-7);    // h = ['a', 'b', 'c'];


var n = [4, 8, 15, 16, 23, 42];
n.sort();  // n = [15, 16, 23, 4, 42, 8];
n.sort(function (a, b) {
    return a - b;
});  // n =  [4, 8, 15, 16, 23, 42];


var m = ['aa', 'bb', 'a', 4, 8, 15, 16, 23, 42];
m.sort(function (a, b) {
    if (a == b) {
        return 0;
    }
    if (typeof a === typeof b) {
        return a < b ? -1 : 1; // 从小到大
    }
    return typeof a < typeof b ? -1 : 1;  // 比较类型
}); // m = [4, 8, 15, 16, 23, 42, "a", "aa", "bb"];


// by 函数接受一个成员名字符串作为参数，并返回一个可以用来对包含该成员的对象数组进行排序的比较函数。
var by = function (name) {
    return function (o, p) {
        var a, b;
        if (typeof o === 'object' && typeof p === 'object' && o && p) {
            a = o[name];
            b = p[name];

            if (a === b) {
                return 0;
            }
            if (typeof a === typeof b) {
                return a < b ? -1 : 1;
            }
            return typeof a < typeof b ? -1 : 1;
        } else {
            throw {
                name: 'Error',
                message: 'Expected on object when sorting by ' + name
            };
        }
    };
};
var s = [
    { first: 'Joe', last: 'Besser' },
    { first: 'Moe', last: 'Howard' },
    { first: 'Joe', last: 'Derita' },
    { first: 'Shemp', last: 'Howard' },
    { first: 'Larry', last: 'Fine' },
    { first: 'Curly', last: 'Howard' },
];
s.sort(by('first'));
/**
 *  s = [
 *      {first: "Curly", last: "Fine"},
 *      {first: "Joe", last: "Besser"},
 *      {first: "Joe", last: "Derita"},
 *      {first: "Larry", last: "Fine"},
 *      {first: "Moe", last: "Howard"},
 *      {first: "Shemp", last: "Howard"}
 * ];
 *  */



var a = ['a', 'b', 'c'];


var a = ['a', 'b', 'c'];